<?php
class PlanoDAO extends DAO{
	
	private $tableName = "tb_plano";
	
	public $conn;
	
	public $prefixo = "";
	
	
	
	public function __construct() {
	
		$this->conn = new CONEXAO();
	}
	
	public function mapear($obj){
		
		$array = $obj->toArray();

		$this->conn->Conecta();
		
		if(!isset($array['id']) || $array['id']==0){
		$array['id'] = $this->conn->maxId($this->tableName,$this->prefixo) + 1;
		}
		$this->conn->Desconecta();

		return $array;
	}
	
	 public function inserir($obj){
	 	
	 	 if(!$obj instanceof Plano){
	 	
	 		throw(new Exception("Dados Inapropriados"));
	 	}

	 	$tableName = $this->tableName;
	 	
			
	 	$comando = DMLGenerator::createInsert($tableName,$this->mapear($obj),$this->prefixo);

	 	$this->conn->Conecta();
	 	$this->conn->Executa($comando);
	 	$this->conn->Desconecta();
	 	
	 	
	 }
	
	 public function buscar($id){
	 	
	 	
	 	
	 }
	
	 public function buscarTodos($obj_pesquisa){}
	
	 public function atualizar($obj){
	 	
	 	if(!$obj instanceof Plano){
	 	
	 		throw(new Exception("Dados Inapropriados"));
	 	}
	 	
	 	$tableName = $this->tableName;
	 	
	 	
	 	$comando = DMLGenerator::createUpdate($tableName,$this->mapear($obj),$this->prefixo);
	 	
	 	$this->conn->Conecta();
	 	$this->conn->Executa($comando);
	 	$this->conn->Desconecta();
	 	
	 	
	 }
	
	 public function apagar($obj){
	 	if(!$obj instanceof Plano){
	 	
	 		throw(new Exception("Dados Inapropriados"));
	 	}
	 	
	 	$tableName = $this->tableName;
	 	
	 	
	 	$comando = DMLGenerator::createDelete($tableName,$obj->getId(),$this->prefixo);
	 	
	 	$this->conn->Conecta();
	 	$this->conn->Executa($comando);
	 	$this->conn->Desconecta();
	 	
	 	
	 }
	
	 public function contem($obj){}
	
	
}